/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.company.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author nguyentien
 */
@Entity
@Table(name = "category_priority")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "CategoryPriority.findAll", query = "SELECT c FROM CategoryPriority c"),
    @NamedQuery(name = "CategoryPriority.findByPriorityId", query = "SELECT c FROM CategoryPriority c WHERE c.priorityId = :priorityId"),
    @NamedQuery(name = "CategoryPriority.findByName", query = "SELECT c FROM CategoryPriority c WHERE c.name = :name")})
public class CategoryPriority implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "priority_id")
    private Integer priorityId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "name")
    private String name;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "priorityId")
    private Collection<Category> categoryCollection;

    public CategoryPriority() {
    }

    public CategoryPriority(Integer priorityId) {
        this.priorityId = priorityId;
    }

    public CategoryPriority(Integer priorityId, String name) {
        this.priorityId = priorityId;
        this.name = name;
    }

    public Integer getPriorityId() {
        return priorityId;
    }

    public void setPriorityId(Integer priorityId) {
        this.priorityId = priorityId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlTransient
    public Collection<Category> getCategoryCollection() {
        return categoryCollection;
    }

    public void setCategoryCollection(Collection<Category> categoryCollection) {
        this.categoryCollection = categoryCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (priorityId != null ? priorityId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CategoryPriority)) {
            return false;
        }
        CategoryPriority other = (CategoryPriority) object;
        if ((this.priorityId == null && other.priorityId != null) || (this.priorityId != null && !this.priorityId.equals(other.priorityId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.company.entity.CategoryPriority[ priorityId=" + priorityId + " ]";
    }
    
}
